package info.webest.media;

import android.content.Context;
import android.media.AudioManager;

public class AudioVolume {

	public int FLAG_SHOW_UI = AudioManager.FLAG_SHOW_UI;

	Context context;
	AudioManager am;
	private int maxVolume = 0;

	public AudioVolume(Context context, boolean ShowUI) {
		this.context = context;
		am = (AudioManager) this.context
				.getSystemService(Context.AUDIO_SERVICE);

		setFlagShowUI(ShowUI);
	}

	public void setFlagShowUI(boolean ShowUI) {
		if (ShowUI) {
			FLAG_SHOW_UI = AudioManager.FLAG_SHOW_UI;
		} else {
			FLAG_SHOW_UI = 0;
		}
	}

	// To get the max volume:
	public int getMax() {
		if (maxVolume == 0) {
			maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
		}
		return maxVolume;
	}

	// To get the current volume:
	public int getCurrent() {
		return am.getStreamVolume(AudioManager.STREAM_MUSIC);
	}

	// To set the current volume:
	public int setCurrent(int v) {
		am.setStreamVolume(AudioManager.STREAM_MUSIC, v, 0);
		return getCurrent();
	}

	// To raise the volume:
	public int rise() {
		// am.adjustStreamVolume(AudioManager.STREAM_MUSIC,
		// AudioManager.ADJUST_RAISE, AudioManager.FLAG_VIBRATE |
		// AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
		am.adjustStreamVolume(AudioManager.STREAM_MUSIC,
				AudioManager.ADJUST_RAISE, FLAG_SHOW_UI);
		return getCurrent();
	}

	// To low the volume:
	public int low() {
		// am.adjustStreamVolume(AudioManager.STREAM_MUSIC,
		// AudioManager.ADJUST_LOWER, AudioManager.FLAG_VIBRATE |
		// AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
		am.adjustStreamVolume(AudioManager.STREAM_MUSIC,
				AudioManager.ADJUST_LOWER, FLAG_SHOW_UI);
		return getCurrent();
	}

	public int mute() {
		int MUTE = 0;
		am.setStreamVolume(AudioManager.STREAM_MUSIC, MUTE, FLAG_SHOW_UI);
		return getCurrent();
	}

}
